package com.wuyi.tea.controller.common;

import com.wuyi.tea.domain.pojo.Category;
import com.wuyi.tea.domain.vo.R;
import com.wuyi.tea.service.CategoryService;
import com.wuyi.tea.util.LocalStorageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@Api(tags = "分类")
@RequestMapping("/category")
@RestController
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @ApiOperation("获取所有商品分类")
    @GetMapping("/list")
    public R list(){
        log.info("id为{}的用户获取了所有商品分类", LocalStorageUtil.get());
        List<Category> categories = categoryService.list();
        return R.success(categories);
    }

    @ApiOperation("获取单个商品分类")
    @GetMapping
    public R getCategoryById(@RequestParam Long id){
        log.info("id为{}的用户获取了单个商品的分类,分类id: {}",LocalStorageUtil.get(),id);
        Category category = categoryService.getById(id);

        return R.success("获取成功",category);
    }


}
